package com.melesta.engine;

import android.os.Bundle;
import android.os.Handler;
import com.facebook.FacebookException;
import com.facebook.FacebookRequestError;
import com.facebook.HttpMethod;
import com.facebook.Request;
import com.facebook.Request.Callback;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.Session.OpenRequest;
import com.facebook.SessionDefaultAudience;
import com.facebook.SessionLoginBehavior;
import com.facebook.model.GraphObject;
import com.facebook.widget.WebDialog.OnCompleteListener;
import com.melesta.facebook.NativeDelegate;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

class FacebookOperations
{
  static final List<String> PUBLISH_PERMISSIONS = Arrays.asList(new String[] { "publish_actions", "publish_stream", "manage_notifications" });
  static final List<String> READ_PERMISSIONS = Arrays.asList(new String[] { "user_likes", "email", "read_stream", "user_games_activity", "friends_games_activity" });
  protected static String mFacebookPageId;
  protected static String mFacebookPageLink;
  protected static String mFacebookPageName;

  static void deleteNotify(String paramString)
  {
    try
    {
      Session localSession = Session.getActiveSession();
      if ((localSession != null) && (localSession.isOpened()))
      {
        if (localSession.isClosed())
          return;
        EngineActivity localEngineActivity = EngineActivity.getInstance();
        if (localEngineActivity != null)
        {
          Bundle localBundle = new Bundle();
          localBundle.putString("method", "delete");
          Helpers.runFbRequestOnUiThread(localEngineActivity, new Request(localSession, paramString, localBundle, HttpMethod.DELETE, new Request.Callback()
          {
            public void onCompleted(Response paramAnonymousResponse)
            {
            }
          }));
          return;
        }
      }
    }
    catch (Exception localException)
    {
      Error.processException("facebookdeleteNotify", localException);
    }
  }

  public static void facebookGetGroupInfo(final String paramString, final int paramInt1, final int paramInt2)
  {
    try
    {
      Session localSession = Session.getActiveSession();
      if ((localSession != null) && (localSession.isOpened()))
      {
        if (localSession.isClosed())
          return;
        EngineActivity localEngineActivity = EngineActivity.getInstance();
        Bundle localBundle = new Bundle();
        localBundle.putString("fields", "id,name,link,likes,picture");
        Helpers.runFbRequestOnUiThread(localEngineActivity, new Request(localSession, paramString, localBundle, null, new Request.Callback()
        {
          public void onCompleted(Response paramAnonymousResponse)
          {
            try
            {
              FacebookRequestError localFacebookRequestError = paramAnonymousResponse.getError();
              int i;
              if (localFacebookRequestError != null)
              {
                i = 1;
                if (i == 0)
                {
                  GraphObject localGraphObject = paramAnonymousResponse.getGraphObject();
                  if (localGraphObject == null)
                    break label180;
                  FacebookOperations.mFacebookPageId = localGraphObject.getProperty("id").toString();
                  FacebookOperations.mFacebookPageName = localGraphObject.getProperty("name").toString();
                  FacebookOperations.mFacebookPageLink = localGraphObject.getProperty("link").toString();
                  final int j = Helpers.goGetIntValue(localGraphObject.getProperty("likes"), -1);
                  final String str = ((JSONObject)localGraphObject.getProperty("picture")).getJSONObject("data").getString("url");
                  this.val$me.runOnGLThread(new Runnable()
                  {
                    public void run()
                    {
                      NativeDelegate.OnGetGroupInfo(0, FacebookOperations.9.this.val$group_id, FacebookOperations.9.this.val$user_data, FacebookOperations.9.this.val$callback, FacebookOperations.mFacebookPageId, FacebookOperations.mFacebookPageName, FacebookOperations.mFacebookPageLink, j, str);
                    }
                  });
                }
              }
              while (true)
              {
                if (i != 0)
                {
                  if (localFacebookRequestError != null)
                  {
                    Log.d("engine", localFacebookRequestError.getErrorType());
                    Log.d("engine", localFacebookRequestError.getErrorMessage());
                  }
                  this.val$me.runOnGLThread(new Runnable()
                  {
                    public void run()
                    {
                      NativeDelegate.OnGetGroupInfo(1, FacebookOperations.9.this.val$group_id, FacebookOperations.9.this.val$user_data, FacebookOperations.9.this.val$callback, null, null, null, -1, null);
                    }
                  });
                }
                return;
                i = 0;
                break;
                label180: i = 1;
              }
            }
            catch (Exception localException)
            {
              Error.processException(localException);
              this.val$me.runOnGLThread(new Runnable()
              {
                public void run()
                {
                  NativeDelegate.OnGetGroupInfo(1, FacebookOperations.9.this.val$group_id, FacebookOperations.9.this.val$user_data, FacebookOperations.9.this.val$callback, null, null, null, -1, null);
                }
              });
            }
          }
        }));
        return;
      }
    }
    catch (Exception localException)
    {
      Error.processException("facebookGetGroupInfo", localException);
    }
  }

  public static void facebookGetUserInfo(String paramString, final int paramInt1, final int paramInt2)
  {
    try
    {
      Session localSession = Session.getActiveSession();
      if ((localSession != null) && (localSession.isOpened()))
      {
        if (localSession.isClosed())
          return;
        final EngineActivity localEngineActivity = EngineActivity.getInstance();
        Bundle localBundle = new Bundle();
        localBundle.putString("fields", "id,name,email,picture");
        Helpers.runFbRequestOnUiThread(localEngineActivity, new Request(localSession, paramString, localBundle, null, new Request.Callback()
        {
          public void onCompleted(Response paramAnonymousResponse)
          {
            try
            {
              FacebookRequestError localFacebookRequestError = paramAnonymousResponse.getError();
              int i;
              if (localFacebookRequestError != null)
              {
                i = 1;
                if (i == 0)
                {
                  GraphObject localGraphObject = paramAnonymousResponse.getGraphObject();
                  if (localGraphObject == null)
                    break label187;
                  final String str1 = localGraphObject.getProperty("id").toString();
                  if (this.val$user_facebook_id.equals("me"))
                    localEngineActivity.mFacebookUserId = str1;
                  final String str2 = localGraphObject.getProperty("name").toString();
                  final String str3 = localGraphObject.getProperty("email").toString();
                  final String str4 = ((JSONObject)localGraphObject.getProperty("picture")).getJSONObject("data").getString("url");
                  localEngineActivity.runOnGLThread(new Runnable()
                  {
                    public void run()
                    {
                      NativeDelegate.OnGetUserInfo(0, FacebookOperations.8.this.val$user_facebook_id, FacebookOperations.8.this.val$user_data, FacebookOperations.8.this.val$callback, str1, str2, str3, str4);
                    }
                  });
                }
              }
              while (true)
              {
                if (i != 0)
                {
                  if (localFacebookRequestError != null)
                  {
                    Log.d("engine", localFacebookRequestError.getErrorType());
                    Log.d("engine", localFacebookRequestError.getErrorMessage());
                  }
                  localEngineActivity.runOnGLThread(new Runnable()
                  {
                    public void run()
                    {
                      NativeDelegate.OnGetUserInfo(1, FacebookOperations.8.this.val$user_facebook_id, FacebookOperations.8.this.val$user_data, FacebookOperations.8.this.val$callback, null, null, null, null);
                    }
                  });
                }
                return;
                i = 0;
                break;
                label187: i = 1;
              }
            }
            catch (Exception localException)
            {
              Error.processException(localException);
              localEngineActivity.runOnGLThread(new Runnable()
              {
                public void run()
                {
                  NativeDelegate.OnGetUserInfo(1, FacebookOperations.8.this.val$user_facebook_id, FacebookOperations.8.this.val$user_data, FacebookOperations.8.this.val$callback, null, null, null, null);
                }
              });
            }
          }
        }));
        return;
      }
    }
    catch (Exception localException)
    {
      Error.processException("facebookGetUserInfo", localException);
    }
  }

  public static void facebookInviteUsersInGame(String paramString1, String paramString2, int paramInt1, int paramInt2)
  {
    try
    {
      EngineActivity localEngineActivity = EngineActivity.getInstance();
      Session localSession = Session.getActiveSession();
      if ((localSession == null) || (!localSession.isOpened()) || (localSession.isClosed()))
      {
        facebookLogin(0, 0);
        return;
      }
      inviteUsersToFacebook(paramString2, paramInt1, paramInt2, localEngineActivity, paramString1);
      return;
    }
    catch (Exception localException)
    {
      Error.processException("facebookInviteUsersInGame", localException);
    }
  }

  public static void facebookIsUserLikedGroup(final String paramString1, String paramString2, final int paramInt1, final int paramInt2)
  {
    try
    {
      Session localSession = Session.getActiveSession();
      if ((localSession != null) && (localSession.isOpened()))
      {
        if (localSession.isClosed())
          return;
        final EngineActivity localEngineActivity = EngineActivity.getInstance();
        String str = paramString1 + "/likes/" + paramString2;
        Request localRequest = new Request(localSession, str, null, null, new Request.Callback()
        {
          public void onCompleted(Response paramAnonymousResponse)
          {
            try
            {
              int i;
              JSONArray localJSONArray;
              final int j;
              if (paramAnonymousResponse.getError() != null)
              {
                i = 1;
                if (i == 0)
                {
                  i = 1;
                  GraphObject localGraphObject = paramAnonymousResponse.getGraphObject();
                  if (localGraphObject != null)
                  {
                    localJSONArray = (JSONArray)localGraphObject.getProperty("data");
                    j = localJSONArray.length();
                  }
                }
              }
              for (int k = j - 1; ; k--)
                if (k >= 0)
                {
                  String str = localJSONArray.getJSONObject(k).getString("id");
                  if (this.val$group_id.equals(str))
                    i = 0;
                }
                else
                {
                  if (i == 0)
                    localEngineActivity.runOnGLThread(new Runnable()
                    {
                      public void run()
                      {
                        String str1 = FacebookOperations.4.this.val$user_id;
                        String str2 = FacebookOperations.4.this.val$group_id;
                        int i = FacebookOperations.4.this.val$user_data;
                        int j = FacebookOperations.4.this.val$callback;
                        if (j > 0);
                        for (boolean bool = true; ; bool = false)
                        {
                          NativeDelegate.OnIsUserLikedGroup(0, str1, str2, i, j, bool);
                          return;
                        }
                      }
                    });
                  if (i != 0)
                    localEngineActivity.runOnGLThread(new Runnable()
                    {
                      public void run()
                      {
                        NativeDelegate.OnIsUserLikedGroup(1, FacebookOperations.4.this.val$user_id, FacebookOperations.4.this.val$group_id, FacebookOperations.4.this.val$user_data, FacebookOperations.4.this.val$callback, false);
                      }
                    });
                  return;
                  i = 0;
                  break;
                }
            }
            catch (Exception localException)
            {
              localEngineActivity.runOnGLThread(new Runnable()
              {
                public void run()
                {
                  NativeDelegate.OnIsUserLikedGroup(1, FacebookOperations.4.this.val$user_id, FacebookOperations.4.this.val$group_id, FacebookOperations.4.this.val$user_data, FacebookOperations.4.this.val$callback, false);
                }
              });
            }
          }
        });
        Helpers.runFbRequestOnUiThread(localEngineActivity, localRequest);
        return;
      }
    }
    catch (Exception localException)
    {
      Error.processException("facebookUpdateInfo", localException);
    }
  }

  // ERROR //
  public static void facebookLike()
  {
    // Byte code:
    //   0: invokestatic 60	com/facebook/Session:getActiveSession	()Lcom/facebook/Session;
    //   3: astore_1
    //   4: aload_1
    //   5: ifnull +17 -> 22
    //   8: aload_1
    //   9: invokevirtual 64	com/facebook/Session:isOpened	()Z
    //   12: ifeq +10 -> 22
    //   15: aload_1
    //   16: invokevirtual 67	com/facebook/Session:isClosed	()Z
    //   19: ifeq +9 -> 28
    //   22: iconst_0
    //   23: iconst_0
    //   24: invokestatic 139	com/melesta/engine/FacebookOperations:facebookLogin	(II)V
    //   27: return
    //   28: invokestatic 73	com/melesta/engine/EngineActivity:getInstance	()Lcom/melesta/engine/EngineActivity;
    //   31: astore_2
    //   32: aload_2
    //   33: invokevirtual 170	com/melesta/engine/EngineActivity:getPackageManager	()Landroid/content/pm/PackageManager;
    //   36: ldc 172
    //   38: iconst_0
    //   39: invokevirtual 178	android/content/pm/PackageManager:getPackageInfo	(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;
    //   42: pop
    //   43: new 147	java/lang/StringBuilder
    //   46: dup
    //   47: invokespecial 148	java/lang/StringBuilder:<init>	()V
    //   50: ldc 180
    //   52: invokevirtual 152	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   55: getstatic 182	com/melesta/engine/FacebookOperations:mFacebookPageId	Ljava/lang/String;
    //   58: invokevirtual 152	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   61: invokevirtual 158	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   64: invokestatic 188	android/net/Uri:parse	(Ljava/lang/String;)Landroid/net/Uri;
    //   67: astore 7
    //   69: aload 7
    //   71: astore 5
    //   73: aload_2
    //   74: new 190	android/content/Intent
    //   77: dup
    //   78: ldc 192
    //   80: aload 5
    //   82: invokespecial 195	android/content/Intent:<init>	(Ljava/lang/String;Landroid/net/Uri;)V
    //   85: invokevirtual 199	com/melesta/engine/EngineActivity:startActivity	(Landroid/content/Intent;)V
    //   88: return
    //   89: astore_0
    //   90: ldc 200
    //   92: aload_0
    //   93: invokestatic 112	com/melesta/engine/Error:processException	(Ljava/lang/String;Ljava/lang/Exception;)V
    //   96: return
    //   97: astore_3
    //   98: new 147	java/lang/StringBuilder
    //   101: dup
    //   102: invokespecial 148	java/lang/StringBuilder:<init>	()V
    //   105: ldc 202
    //   107: invokevirtual 152	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   110: getstatic 182	com/melesta/engine/FacebookOperations:mFacebookPageId	Ljava/lang/String;
    //   113: invokevirtual 152	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   116: invokevirtual 158	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   119: invokestatic 188	android/net/Uri:parse	(Ljava/lang/String;)Landroid/net/Uri;
    //   122: astore 4
    //   124: aload 4
    //   126: astore 5
    //   128: goto -55 -> 73
    //
    // Exception table:
    //   from	to	target	type
    //   0	4	89	java/lang/Exception
    //   8	22	89	java/lang/Exception
    //   22	27	89	java/lang/Exception
    //   28	32	89	java/lang/Exception
    //   73	88	89	java/lang/Exception
    //   98	124	89	java/lang/Exception
    //   32	69	97	java/lang/Exception
  }

  static void facebookLogin(int paramInt1, int paramInt2)
  {
    try
    {
      EngineActivity localEngineActivity = EngineActivity.getInstance();
      Session localSession = Session.getActiveSession();
      localEngineActivity.getClass();
      EngineActivity.SessionStatusCallback localSessionStatusCallback = new EngineActivity.SessionStatusCallback(localEngineActivity, paramInt1, paramInt2);
      Session.OpenRequest localOpenRequest = new Session.OpenRequest(localEngineActivity).setCallback(localSessionStatusCallback);
      if (localOpenRequest != null)
      {
        localOpenRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
        localOpenRequest.setPermissions(READ_PERMISSIONS);
        localOpenRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
      }
      if ((!localSession.isOpened()) && (!localSession.isClosed()))
      {
        localSession.openForRead(localOpenRequest);
        return;
      }
      Session.openActiveSession(localEngineActivity, true, localSessionStatusCallback);
      return;
    }
    catch (Exception localException)
    {
      Error.processException("facebookLogin", localException);
    }
  }

  public static void facebookPost(String paramString, final int paramInt1, final int paramInt2)
  {
    try
    {
      final EngineActivity localEngineActivity = EngineActivity.getInstance();
      Session localSession = Session.getActiveSession();
      if ((localSession == null) || (!localSession.isOpened()) || (localSession.isClosed()))
      {
        facebookLogin(0, 0);
        return;
      }
      localEngineActivity.mHandler.post(new Runnable()
      {
        public void run()
        {
          try
          {
            Bundle localBundle = new Bundle();
            localBundle.putString("link", FacebookOperations.mFacebookPageLink);
            localBundle.putString("name", FacebookOperations.mFacebookPageName);
            localBundle.putString("caption", FacebookOperations.mFacebookPageName);
            localBundle.putString("description", this.val$body);
            Helpers.showFeedDialogWithoutNotificationBar(localEngineActivity, localBundle, new WebDialog.OnCompleteListener()
            {
              private void onPosted(final boolean paramAnonymous2Boolean, final int paramAnonymous2Int1, final int paramAnonymous2Int2)
              {
                EngineActivity.getInstance().runOnGLThread(new Runnable()
                {
                  public void run()
                  {
                    NativeDelegate.OnPosted(paramAnonymous2Boolean, paramAnonymous2Int1, paramAnonymous2Int2);
                  }
                });
              }

              public void onComplete(Bundle paramAnonymous2Bundle, FacebookException paramAnonymous2FacebookException)
              {
                if ((paramAnonymous2FacebookException == null) && (paramAnonymous2Bundle != null) && (paramAnonymous2Bundle.size() > 0));
                for (boolean bool = true; ; bool = false)
                {
                  onPosted(bool, FacebookOperations.10.this.val$user_data, FacebookOperations.10.this.val$callback);
                  return;
                }
              }
            });
            return;
          }
          catch (Exception localException)
          {
            Error.processException("facebookPost-handler", localException);
          }
        }
      });
      return;
    }
    catch (Exception localException)
    {
      Error.processException("facebookPost", localException);
    }
  }

  public static void facebookSendRequest(String paramString1, final String paramString2, final String paramString3, final boolean paramBoolean, final int paramInt1, final int paramInt2)
  {
    try
    {
      final EngineActivity localEngineActivity = EngineActivity.getInstance();
      Session localSession = Session.getActiveSession();
      if ((localSession == null) || (!localSession.isOpened()) || (localSession.isClosed()))
      {
        facebookLogin(0, 0);
        return;
      }
      localEngineActivity.mHandler.post(new Runnable()
      {
        public void run()
        {
          try
          {
            Bundle localBundle = new Bundle();
            String str = FacebookOperations.truncIdList(this.val$friends);
            localBundle.putString("data", paramString3);
            localBundle.putString("message", paramString2);
            localBundle.putString("link", FacebookOperations.mFacebookPageLink);
            localBundle.putString("name", FacebookOperations.mFacebookPageName);
            localBundle.putString("title", FacebookOperations.mFacebookPageName);
            if ((str != null) && (str.length() > 0))
            {
              localBundle.putString("frictionless", "1");
              if (!paramBoolean)
                break label136;
              localBundle.putString("filters", "[user_ids: [" + str + "]]");
            }
            while (true)
            {
              Helpers.showRequestDialogWithoutNotificationBar(localEngineActivity, localBundle, new WebDialog.OnCompleteListener()
              {
                private void onPosted(final boolean paramAnonymous2Boolean, final String paramAnonymous2String, final int paramAnonymous2Int1, final int paramAnonymous2Int2)
                {
                  EngineActivity.getInstance().runOnGLThread(new Runnable()
                  {
                    public void run()
                    {
                      NativeDelegate.OnSendRequest(paramAnonymous2Boolean, paramAnonymous2String, FacebookOperations.6.this.val$data, paramAnonymous2Int1, paramAnonymous2Int2);
                    }
                  });
                }

                public void onComplete(Bundle paramAnonymous2Bundle, FacebookException paramAnonymous2FacebookException)
                {
                  boolean bool;
                  if ((paramAnonymous2FacebookException == null) && (paramAnonymous2Bundle != null) && (paramAnonymous2Bundle.size() > 0))
                  {
                    bool = true;
                    if (!bool)
                      break label54;
                  }
                  label54: for (String str = FacebookOperations.getUserIdsForWhomRequestWasSended(paramAnonymous2Bundle); ; str = null)
                  {
                    onPosted(bool, str, FacebookOperations.6.this.val$user_data, FacebookOperations.6.this.val$callback);
                    return;
                    bool = false;
                    break;
                  }
                }
              });
              return;
              label136: localBundle.putString("to", str);
            }
          }
          catch (Exception localException)
          {
            Error.processException("facebookSendRequest-handler", localException);
          }
        }
      });
      return;
    }
    catch (Exception localException)
    {
      Error.processException("facebookSendRequest", localException);
    }
  }

  public static void facebookSendRequestToFriends(String paramString1, final String paramString2, final String paramString3, final boolean paramBoolean, final int paramInt1, final int paramInt2)
  {
    try
    {
      final EngineActivity localEngineActivity = EngineActivity.getInstance();
      Session localSession = Session.getActiveSession();
      if ((localSession == null) || (!localSession.isOpened()) || (localSession.isClosed()))
      {
        facebookLogin(0, 0);
        return;
      }
      localEngineActivity.mHandler.post(new Runnable()
      {
        public void run()
        {
          try
          {
            Bundle localBundle = new Bundle();
            String str = FacebookOperations.truncIdList(this.val$friends);
            localBundle.putString("data", paramString3);
            localBundle.putString("message", paramString2);
            localBundle.putString("link", FacebookOperations.mFacebookPageLink);
            localBundle.putString("name", FacebookOperations.mFacebookPageName);
            localBundle.putString("title", FacebookOperations.mFacebookPageName);
            if ((str != null) && (str.length() > 0))
            {
              localBundle.putString("frictionless", "1");
              if (!paramBoolean)
                break label136;
              localBundle.putString("filters", "[user_ids: [" + str + "]]");
            }
            while (true)
            {
              Helpers.showRequestDialogWithoutNotificationBar(localEngineActivity, localBundle, new WebDialog.OnCompleteListener()
              {
                private void onPosted(final boolean paramAnonymous2Boolean, final String paramAnonymous2String, final int paramAnonymous2Int1, final int paramAnonymous2Int2)
                {
                  EngineActivity.getInstance().runOnGLThread(new Runnable()
                  {
                    public void run()
                    {
                      NativeDelegate.OnSendRequestToFriends(paramAnonymous2Boolean, paramAnonymous2String, FacebookOperations.5.this.val$data, paramAnonymous2Int1, paramAnonymous2Int2);
                    }
                  });
                }

                public void onComplete(Bundle paramAnonymous2Bundle, FacebookException paramAnonymous2FacebookException)
                {
                  boolean bool;
                  if ((paramAnonymous2FacebookException == null) && (paramAnonymous2Bundle != null) && (paramAnonymous2Bundle.size() > 0))
                  {
                    bool = true;
                    if (!bool)
                      break label54;
                  }
                  label54: for (String str = FacebookOperations.getUserIdsForWhomRequestWasSended(paramAnonymous2Bundle); ; str = null)
                  {
                    onPosted(bool, str, FacebookOperations.5.this.val$user_data, FacebookOperations.5.this.val$callback);
                    return;
                    bool = false;
                    break;
                  }
                }
              });
              return;
              label136: localBundle.putString("to", str);
            }
          }
          catch (Exception localException)
          {
            Error.processException("facebookPost-handler", localException);
          }
        }
      });
      return;
    }
    catch (Exception localException)
    {
      Error.processException("facebookPost", localException);
    }
  }

  public static void facebookSetUserScore(String paramString, int paramInt1, int paramInt2, int paramInt3)
  {
    try
    {
      Session localSession = Session.getActiveSession();
      if ((localSession != null) && (localSession.isOpened()))
      {
        if (localSession.isClosed())
          return;
        EngineActivity localEngineActivity = EngineActivity.getInstance();
        Bundle localBundle = new Bundle();
        localBundle.putInt("score", paramInt1);
        Helpers.runFbRequestOnUiThread(localEngineActivity, new Request(localSession, "/me/scores", localBundle, null, new Request.Callback()
        {
          public void onCompleted(Response paramAnonymousResponse)
          {
            Log.d("facebook", "Score updated");
            try
            {
              FacebookRequestError localFacebookRequestError = paramAnonymousResponse.getError();
              if (localFacebookRequestError != null);
              return;
            }
            catch (Exception localException)
            {
              Error.processException(localException);
              this.val$me.runOnGLThread(new Runnable()
              {
                public void run()
                {
                }
              });
            }
          }
        }));
        return;
      }
    }
    catch (Exception localException)
    {
      Error.processException("facebookGetUserInfo", localException);
    }
  }

  public static void getUserFriends(final String paramString, final int paramInt1, final int paramInt2)
  {
    while (true)
    {
      try
      {
        Session localSession = Session.getActiveSession();
        if ((localSession == null) || (!localSession.isOpened()))
          break;
        if (localSession.isClosed())
          return;
        EngineActivity localEngineActivity = EngineActivity.getInstance();
        Bundle localBundle = new Bundle();
        Object[] arrayOfObject = new Object[1];
        if (paramString.length() > 0)
        {
          str = paramString;
          arrayOfObject[0] = str;
          localBundle.putString("q", String.format("SELECT uid, name, is_app_user, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = %s)", arrayOfObject));
          Helpers.runFbRequestOnUiThread(localEngineActivity, new Request(localSession, "/fql", localBundle, null, new Request.Callback()
          {
            public void onCompleted(Response paramAnonymousResponse)
            {
              for (int i = 1; ; i = 0)
                try
                {
                  FacebookRequestError localFacebookRequestError = paramAnonymousResponse.getError();
                  if (localFacebookRequestError != null)
                  {
                    if (i == 0)
                    {
                      GraphObject localGraphObject = paramAnonymousResponse.getGraphObject();
                      if (localGraphObject == null)
                        break label200;
                      JSONArray localJSONArray = (JSONArray)localGraphObject.getProperty("data");
                      int j = localJSONArray.length();
                      final Object[][] arrayOfObject = (Object[][])Array.newInstance(Object.class, new int[] { j, 3 });
                      for (int k = 0; k < j; k++)
                      {
                        JSONObject localJSONObject = localJSONArray.getJSONObject(k);
                        arrayOfObject[k][0] = localJSONObject.getString("uid");
                        arrayOfObject[k][1] = localJSONObject.getString("name");
                        arrayOfObject[k][2] = localJSONObject.getString("pic_square");
                      }
                      this.val$me.runOnGLThread(new Runnable()
                      {
                        public void run()
                        {
                          NativeDelegate.OnGetUserFriends(0, FacebookOperations.1.this.val$user_facebook_id, FacebookOperations.1.this.val$user_data, FacebookOperations.1.this.val$callback, arrayOfObject);
                        }
                      });
                    }
                    while (true)
                    {
                      if (i != 0)
                      {
                        if (localFacebookRequestError != null)
                        {
                          Log.d("engine", localFacebookRequestError.getErrorType());
                          Log.d("engine", localFacebookRequestError.getErrorMessage());
                        }
                        this.val$me.runOnGLThread(new Runnable()
                        {
                          public void run()
                          {
                            NativeDelegate.OnGetUserFriends(1, FacebookOperations.1.this.val$user_facebook_id, FacebookOperations.1.this.val$user_data, FacebookOperations.1.this.val$callback, (Object[][])null);
                          }
                        });
                      }
                      return;
                      label200: i = 1;
                    }
                  }
                }
                catch (Exception localException)
                {
                  Error.processException(localException);
                  this.val$me.runOnGLThread(new Runnable()
                  {
                    public void run()
                    {
                      NativeDelegate.OnGetUserFriends(1, FacebookOperations.1.this.val$user_facebook_id, FacebookOperations.1.this.val$user_data, FacebookOperations.1.this.val$callback, (Object[][])null);
                    }
                  });
                  return;
                }
            }
          }));
          return;
        }
      }
      catch (Exception localException)
      {
        Error.processException("facebookGetUserInfo", localException);
        return;
      }
      String str = "me()";
    }
  }

  public static void getUserGameFriends(final String paramString, final int paramInt1, final int paramInt2)
  {
    while (true)
    {
      try
      {
        Session localSession = Session.getActiveSession();
        if ((localSession == null) || (!localSession.isOpened()))
          break;
        if (localSession.isClosed())
          return;
        EngineActivity localEngineActivity = EngineActivity.getInstance();
        Bundle localBundle = new Bundle();
        Object[] arrayOfObject = new Object[1];
        if (paramString.length() > 0)
        {
          str = paramString;
          arrayOfObject[0] = str;
          localBundle.putString("q", String.format("SELECT uid, name, is_app_user, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = %s) AND is_app_user = 1", arrayOfObject));
          Helpers.runFbRequestOnUiThread(localEngineActivity, new Request(localSession, "/fql", localBundle, null, new Request.Callback()
          {
            public void onCompleted(Response paramAnonymousResponse)
            {
              for (int i = 1; ; i = 0)
                try
                {
                  FacebookRequestError localFacebookRequestError = paramAnonymousResponse.getError();
                  if (localFacebookRequestError != null)
                  {
                    if (i == 0)
                    {
                      GraphObject localGraphObject = paramAnonymousResponse.getGraphObject();
                      if (localGraphObject == null)
                        break label200;
                      JSONArray localJSONArray = (JSONArray)localGraphObject.getProperty("data");
                      int j = localJSONArray.length();
                      final Object[][] arrayOfObject = (Object[][])Array.newInstance(Object.class, new int[] { j, 3 });
                      for (int k = 0; k < j; k++)
                      {
                        JSONObject localJSONObject = localJSONArray.getJSONObject(k);
                        arrayOfObject[k][0] = localJSONObject.getString("uid");
                        arrayOfObject[k][1] = localJSONObject.getString("name");
                        arrayOfObject[k][2] = localJSONObject.getString("pic_square");
                      }
                      this.val$me.runOnGLThread(new Runnable()
                      {
                        public void run()
                        {
                          NativeDelegate.OnGetUserGameFriends(0, FacebookOperations.2.this.val$user_facebook_id, FacebookOperations.2.this.val$user_data, FacebookOperations.2.this.val$callback, arrayOfObject);
                        }
                      });
                    }
                    while (true)
                    {
                      if (i != 0)
                      {
                        if (localFacebookRequestError != null)
                        {
                          Log.d("engine", localFacebookRequestError.getErrorType());
                          Log.d("engine", localFacebookRequestError.getErrorMessage());
                        }
                        this.val$me.runOnGLThread(new Runnable()
                        {
                          public void run()
                          {
                            NativeDelegate.OnGetUserGameFriends(1, FacebookOperations.2.this.val$user_facebook_id, FacebookOperations.2.this.val$user_data, FacebookOperations.2.this.val$callback, (Object[][])null);
                          }
                        });
                      }
                      return;
                      label200: i = 1;
                    }
                  }
                }
                catch (Exception localException)
                {
                  Error.processException(localException);
                  this.val$me.runOnGLThread(new Runnable()
                  {
                    public void run()
                    {
                      NativeDelegate.OnGetUserGameFriends(1, FacebookOperations.2.this.val$user_facebook_id, FacebookOperations.2.this.val$user_data, FacebookOperations.2.this.val$callback, (Object[][])null);
                    }
                  });
                  return;
                }
            }
          }));
          return;
        }
      }
      catch (Exception localException)
      {
        Error.processException("facebookGetUserInfo", localException);
        return;
      }
      String str = "me()";
    }
  }

  private static String getUserIdsForWhomRequestWasSended(Bundle paramBundle)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    for (int i = 0; ; i++)
    {
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = Integer.valueOf(i);
      String str = paramBundle.getString(String.format("to[%d]", arrayOfObject));
      if (str == null)
        return localStringBuilder.toString();
      if (localStringBuilder.length() > 0)
        localStringBuilder.append(',');
      localStringBuilder.append(str);
    }
  }

  private static void inviteUsersToFacebook(String paramString1, final int paramInt1, final int paramInt2, final EngineActivity paramEngineActivity, String paramString2)
  {
    paramEngineActivity.runOnUiThread(new Runnable()
    {
      public void run()
      {
        try
        {
          Bundle localBundle = new Bundle();
          localBundle.putString("link", FacebookOperations.mFacebookPageLink);
          localBundle.putString("name", FacebookOperations.mFacebookPageName);
          localBundle.putString("title", FacebookOperations.mFacebookPageName);
          localBundle.putStringArray("filters", new String[] { "app_non_users" });
          localBundle.putString("message", this.val$body);
          if ((this.val$suggestions != null) && (this.val$suggestions.length() > 0))
          {
            localBundle.putString("frictionless", "1");
            localBundle.putString("to", this.val$suggestions);
          }
          Helpers.showRequestDialogWithoutNotificationBar(paramEngineActivity, localBundle, new WebDialog.OnCompleteListener()
          {
            private void onInvited(final boolean paramAnonymous2Boolean, final String paramAnonymous2String, final int paramAnonymous2Int1, final int paramAnonymous2Int2)
            {
              EngineActivity.getInstance().runOnGLThread(new Runnable()
              {
                public void run()
                {
                  NativeDelegate.OnUsersInvited(paramAnonymous2Boolean, paramAnonymous2String, paramAnonymous2Int1, paramAnonymous2Int2);
                }
              });
            }

            public void onComplete(Bundle paramAnonymous2Bundle, FacebookException paramAnonymous2FacebookException)
            {
              boolean bool;
              if (paramAnonymous2FacebookException == null)
              {
                bool = true;
                if (!bool)
                  break label43;
              }
              label43: for (String str = FacebookOperations.getUserIdsForWhomRequestWasSended(paramAnonymous2Bundle); ; str = null)
              {
                onInvited(bool, str, FacebookOperations.3.this.val$user_data, FacebookOperations.3.this.val$callback);
                return;
                bool = false;
                break;
              }
            }
          });
          return;
        }
        catch (Exception localException)
        {
          Error.processException("facebookPost-handler", localException);
        }
      }
    });
  }

  static void receiveNotify(final int paramInt1, final int paramInt2)
  {
    try
    {
      Session localSession = Session.getActiveSession();
      if ((localSession != null) && (localSession.isOpened()))
      {
        if (localSession.isClosed())
          return;
        EngineActivity localEngineActivity = EngineActivity.getInstance();
        Helpers.runFbRequestOnUiThread(localEngineActivity, Request.newGraphPathRequest(localSession, "me/apprequests", new Request.Callback()
        {
          public void onCompleted(Response paramAnonymousResponse)
          {
            int i;
            try
            {
              if (paramAnonymousResponse.getError() != null)
              {
                i = 1;
                break label156;
                GraphObject localGraphObject = paramAnonymousResponse.getGraphObject();
                if (localGraphObject != null)
                {
                  JSONArray localJSONArray = (JSONArray)localGraphObject.getProperty("data");
                  int j = localJSONArray.length();
                  for (int k = 0; k < j; k++)
                  {
                    JSONObject localJSONObject = localJSONArray.getJSONObject(k);
                    final String str1 = localJSONObject.getString("id");
                    final String str2 = localJSONObject.getJSONObject("from").getString("id");
                    final String str3 = localJSONObject.getString("data");
                    if ((str3 != null) && (str3.length() > 0))
                      this.val$me.runOnGLThread(new Runnable()
                      {
                        public void run()
                        {
                          if (NativeDelegate.OnRecieveNotify(0, str2, str3, FacebookOperations.11.this.val$user_data, FacebookOperations.11.this.val$callback))
                            FacebookOperations.deleteNotify(str1);
                        }
                      });
                  }
                }
              }
            }
            catch (Exception localException)
            {
              Error.processException(localException);
              this.val$me.runOnGLThread(new Runnable()
              {
                public void run()
                {
                  NativeDelegate.OnRecieveNotify(1, null, null, FacebookOperations.11.this.val$user_data, FacebookOperations.11.this.val$callback);
                }
              });
              return;
            }
            label156: 
            while (i != 0)
            {
              return;
              i = 0;
            }
          }
        }));
        return;
      }
    }
    catch (Exception localException)
    {
      Error.processException("facebookReceiveNotify", localException);
    }
  }

  static String truncIdList(String paramString)
  {
    int i = 0;
    int j = paramString.length();
    int k = 0;
    if (k < j)
    {
      if (paramString.charAt(k) != ',');
      do
      {
        k++;
        break;
        i++;
      }
      while (i != 50);
      paramString = paramString.substring(0, k);
    }
    return paramString;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.melesta.engine.FacebookOperations
 * JD-Core Version:    0.6.2
 */